package com.qfedu.mavenk.beanDemo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import org.springframework.stereotype.Service;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc: 测试bean依赖，体现两个class之间产生的关系
 * @datatime: 2022/10/20 9:33
 */
public class App04 {
    private Service mainService;
    private Service[] services;

    //构造注入
    public App04(Service main){
        this.mainService = main;
    }

    public App04(Service[] main){
        this.services = main;
    }

    //set方法注入
    public void setMainService(Service mainService) {
        this.mainService = mainService;
    }

    public void setServices(Service[] services) {
        this.services = services;
    }

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
        App04 app04 = (App04) context.getBean("app04");
        System.out.println(app04.mainService.value());
        System.out.println(app04.services.length);
        ((ClassPathXmlApplicationContext)context).close();
    }
}
